package com.fzy.modules.goods.web;

import com.fzy.core.common.ApiController;
import com.fzy.core.common.ResponseData;
import com.fzy.modules.goods.entity.GoodsBom;
import com.fzy.modules.goods.service.GoodsBomService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 子商品Controller
 */
@RestController
@RequestMapping(value = "/api/goods/bom")
public class GoodsBomController extends ApiController{
    @Autowired
    GoodsBomService goodsBomService;
    @GetMapping(value = "/{goodsId}")
    public ResponseEntity<ResponseData> list(@PathVariable String goodsId){
        return new ResponseEntity<>(success(goodsBomService.findAllList(goodsId)), HttpStatus.OK);
    }
    @PostMapping(value = "")
    public ResponseEntity<ResponseData> save( GoodsBom goodsBom ) {
        if (StringUtils.isNotEmpty(goodsBom.getId())) {
            return new ResponseEntity<>(success(goodsBomService.update(goodsBom)), HttpStatus.OK);
        }
        return new ResponseEntity<>(success(goodsBomService.save(goodsBom)), HttpStatus.OK);
    }
    @DeleteMapping(value = "/{id}")
    public ResponseEntity<ResponseData> delete(@PathVariable String id) {
        return new ResponseEntity<>(success(goodsBomService.delete(id)), HttpStatus.OK);
    }
}
